import request from '../utils/request'
import type { DepartInfo, ApiResponse, ParkInfo, ListResponse } from '../types/api'

export interface ListQuery {
  pageNo: number
  pageSize: number
  zybLaneDto?: {
    id?: string
    departName?: string
    parkName?: string
    parkId?: string
    name?: string
    number?: string
    type?: number
    serialNumber?: string
    linkserialNumber?: string
    depId?: string
    userId?: string
  }
}

export interface DepartListQuery {
  userId: string,
  parentId: string,
  parentProjId: string,
  departName: string,
  orgCategory: number
}

export interface ParkinfoListQuery {
  userId: string,
  depId: string,
  name: string,
  parentId: string
}

// 获取列表数据
export function getList(params: ListQuery): Promise<ApiResponse<ListResponse>> {
  return request({
    url: '/sys/list',
    method: 'post',
    params
  })
}

export function getDepartList(params: DepartListQuery): Promise<ApiResponse<DepartInfo[]>> {
  return request({
    url: '/sys/getSysDepartList',
    method: 'post',
    params
  })
}

export function getParkInfoList(params: ParkinfoListQuery): Promise<ApiResponse<ParkInfo[]>> {
  return request({    
    url: '/sys/getParkinfoList',
    method: 'post',
    params
  })
}

// 操作开闸、长开、重启等
export type OperationQuery = {
  sid?: string,
  /** 使用serialNumber */
  sn: string,
  /** 0 - 开闸； 1 - 关闸 */
  state: 0 | 1, 
  type?: number,
  /** 使用 id: 用于常开/关 */
  lanId?: string
}

export function operateOpen(params: OperationQuery): Promise<ApiResponse<any>> {
  return request({
    url: '/sos/open',
    method: 'post',
    params
  })
}

export function operateKeepAlive(params: OperationQuery): Promise<ApiResponse<any>> {
  return request({
    url: '/sos/changkai',
    method: 'post',
    params
  })
}

export function operateReboot(params: OperationQuery): Promise<ApiResponse<any>> {
  return request({
    url: '/sos/reboot',
    method: 'post',
    params
  })
}

export function openAll(depId: string): Promise<ApiResponse<any>> {
  return request({
    url: '/sos/allOpen',
    method: 'post',
    params: { depId }
  })
}